package com.moi.summer;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class CharacterListView extends Fragment implements AdapterView.OnItemClickListener {

    private ListView charcterListView;
    private List<Character> characterList = new ArrayList<Character>();
    public CharacterAdapter characterAdapter;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.list_view_layout, container, false);
        View titleView = inflater.inflate(R.layout.item_header, container, false);
        characterAdapter = new CharacterAdapter(getActivity(), R.layout.character_item, characterList);
        charcterListView = (ListView) view.findViewById(R.id.lv);
        charcterListView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        titleView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                ListView.LayoutParams.WRAP_CONTENT));
        charcterListView.addHeaderView(titleView);
        charcterListView.addFooterView(titleView);
        charcterListView.setAdapter(characterAdapter);
        charcterListView.setOnItemClickListener(this);

        initCharacters();
        return view;
    }

    private void initCharacters() {
        for (int i = 0; i < 5; i++) {
            Character yhw = new Character("余汇雯", "♀","一个神奇的人物，就算是我也猜不透。");
            characterList.add(yhw);
            Character yy = new Character("云云", "♀","仅次于余汇雯的神奇人物，至今不知其姓。");
            characterList.add(yy);
            Character zs = new Character("周顺", "♂","这货是男主？");
            characterList.add(zs);
            Character xxc = new Character("徐晓川", "♂","一个神出鬼没的冒险家。");
            characterList.add(xxc);
            Character xxl = new Character("徐晓林", "♀","神出鬼没的冒险家徐哮喘的妹妹。");
            characterList.add(xxl);
            Character zy = new Character("张叶", "♂","遛狗的。");
            characterList.add(zy);
            Character wy = new Character("阿非", "♂","猥猥琐琐的玩家角色。");
            characterList.add(wy);
            Character jj = new Character("双胞胎姐姐", "♀","咖啡店老板（大一号的）。");
            characterList.add(jj);
            Character mm = new Character("双胞胎妹妹", "♀","咖啡店老板（小一号的）。");
            characterList.add(mm);
            Character cat = new Character("徐晓川的猫", "？","喵~喵~喵~");
            characterList.add(cat);
            Character dog = new Character("张叶的狗", "？","汪！汪！汪！");
            characterList.add(dog);
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Character character = characterList.get(position);
        CharacterContentActivity.actionStart(getActivity(), character.getName(), character.getConetent());
    }
}
